home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / IBTip / Source / Source.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  1010 b   |  67 lines

  1. #import "Source.h"
  2. #import <stdio.h>
  3. #import <stdlib.h>
  4. #import <string.h>
  5.  
  6. @implementation Source
  7.   
  8. + newStrings:(char **)s
  9. {
  10.   int i;
  11.   self = [super new];
  12.   for(nlines=0; s[nlines]; nlines++)
  13.     ;
  14.   lines = malloc(nlines*sizeof(char *));
  15.   for(i=0; i<nlines; i++) {
  16.     lines[i] = malloc(strlen(s[i])+1);
  17.     strcpy(lines[i],s[i]);
  18.   }
  19.   lp=0;
  20.   return self;
  21. }
  22.  
  23. - (int)getchar
  24. {
  25.   if (lp >= nlines)
  26.     return EOF;
  27.   else
  28.     return *lines[lp++];
  29. }
  30.  
  31. - (int)getcharWithPrompt:(char *)prompt
  32. {
  33.   return [self getchar];
  34. }
  35.  
  36. - (int)getline:(char *)string size:(int)max
  37. {
  38.   if (lp >= nlines) {
  39.     *string=0;
  40.     return 0;
  41.   }
  42.   else
  43.     strncpy(string, lines[lp++], max-1);
  44.   string[max-1]=0;
  45.   return(strlen(string));
  46. }
  47.   
  48.     
  49. - (int)getline:(char *)string size:(int)max WithPrompt:(char *)prompt
  50. {
  51.   return [self getline:string size:max];
  52. }
  53.  
  54. - putString:(char *)string; // no op for Source
  55. {
  56.   return self;
  57. }
  58.  
  59. -free
  60. {
  61.   int i;
  62.   for (i=nlines-1; i>=0; i--)
  63.     free(lines[i]);
  64.   return [super free];
  65. }
  66. @end
  67.